package com.yanfan.patrol.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.patrol.domain.IbmsPatrolRoute;
import com.yanfan.patrol.service.IIbmsPatrolRouteService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 巡更路线Controller
 *
 * @author lzb
 * @date 2024-08-26
 */
@Api(tags = "巡更路线")
@RestController
@RequestMapping("/patrol/route")
public class IbmsPatrolRouteController extends BaseController {
    @Autowired
    private IIbmsPatrolRouteService ibmsPatrolRouteService;

    /**
     * 查询巡更路线列表
     */
    @ApiOperation("巡更路线分页列表")
    @PreAuthorize("@ss.hasPermi('patrol:route:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsPatrolRoute ibmsPatrolRoute) {
        startPage();
        List<IbmsPatrolRoute> list = ibmsPatrolRouteService.queryPageList(ibmsPatrolRoute);
        return getDataTable(list);
    }

    /**
     * 导出巡更路线列表
     */
    @ApiOperation("导出巡更路线列表")
    @PreAuthorize("@ss.hasPermi('patrol:route:export')")
    @Log(title = "巡更路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsPatrolRoute ibmsPatrolRoute) {
        List<IbmsPatrolRoute> list = ibmsPatrolRouteService.queryPageList(ibmsPatrolRoute);
        ExcelUtil<IbmsPatrolRoute> util = new ExcelUtil<IbmsPatrolRoute>(IbmsPatrolRoute.class);
        util.exportExcel(response, list, "巡更路线数据");
    }

    /**
     * 获取巡更路线详细信息
     */
    @ApiOperation("获取巡更路线详细信息")
    @PreAuthorize("@ss.hasPermi('patrol:route:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsPatrolRouteService.getById(id));
    }

    /**
     * 新增巡更路线
     */
    @ApiOperation("新增巡更路线")
    @PreAuthorize("@ss.hasPermi('patrol:route:add')")
    @Log(title = "巡更路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsPatrolRoute ibmsPatrolRoute) {
        return toAjax(ibmsPatrolRouteService.save(ibmsPatrolRoute));
    }

    /**
     * 修改巡更路线
     */
    @ApiOperation("修改巡更路线")
    @PreAuthorize("@ss.hasPermi('patrol:route:edit')")
    @Log(title = "巡更路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsPatrolRoute ibmsPatrolRoute) {
        return toAjax(ibmsPatrolRouteService.updateById(ibmsPatrolRoute));
    }

    /**
     * 删除巡更路线
     */
    @ApiOperation("删除巡更路线")
    @PreAuthorize("@ss.hasPermi('patrol:route:remove')")
    @Log(title = "巡更路线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsPatrolRouteService.removeBatchByIds(Arrays.asList(ids)));
    }
}
